import {ElMessage, ElMessageBox} from "element-plus";

const handleDel = (tips = "", delAction, delParams,flag=false) => {
    if(flag==true) {
        ElMessageBox.confirm(`确定${tips}吗？`, "提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            beforeClose: (action, instance, done) => {
                if (action === "confirm") {
                    // 开启按钮加载
                    instance.confirmButtonLoading = true;
                    // 删除接口
                    delAction(delParams)
                        .then(res => {
                            if (res.data.success === true) {
                                ElMessage.success("操作成功");
                                // getList();
                                done();
                            }
                        })
                        .catch(() => {
                        })
                        .finally(() => {
                            // 接口回调结束，关闭按钮加载
                            instance.confirmButtonLoading = false;
                        });
                } else {
                    done();
                }
            },
        }).catch(() => {
        })
    }
}
export default handleDel
